package de.ubschmidt.capi.util;

/**
 *
 */
public final class Bits {

    private Bits() {
    }

    /**
     *
     * @param position
     * @return
     */
    public static int getBitValue(final int position) {
        return (1 << position);
    }

    /**
     *
     * @param value
     * @param position
     * @return
     */
    public static boolean isBitSet(final int value, final int position) {
        return (value & getBitValue(position)) != 0;
    }

    /**
     *
     * @param value
     * @param position
     * @return
     */
    public static int setBit(final int value, final int position) {
        return (value | getBitValue(position));
    }

    /**
     *
     * @param value
     * @param position
     * @return
     */
    public static int clearBit(final int value, final int position) {
        return (value & (0xffffffff ^ getBitValue(position)));
    }

}
